package com.mapper;

import com.pojo.Products;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductsMapper {

    @Insert("INSERT INTO products(name, description, price, cover_url, available, created_at, updated_at) " +
            "VALUES(#{name}, #{description}, #{price}, #{coverUrl}, #{available}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Products product);

    @Update("UPDATE products SET " +
            "name = #{name}, " +
            "description = #{description}, " +
            "price = #{price}, " +
            "cover_url = #{coverUrl}, " +
            "available = #{available}, " +
            "updated_at = #{updatedAt} " +
            "WHERE id = #{id}")
    int update(Products product);

    @Delete("DELETE FROM products WHERE id = #{id}")
    int delete(Integer id);

    @Select("SELECT * FROM products WHERE id = #{id}")
    Products selectById(Integer id);

    @Select("SELECT * FROM products")
    List<Products> selectAll();

    @Select("SELECT * FROM products WHERE available = true")
    List<Products> selectAvailable();



}